package com.lvandroid.play.util;

import android.graphics.Point;
import android.graphics.PointF;
import android.util.Size;

/**
 * 尺寸相关工具类，尺寸转换计算
 */
public class SizeUtil {

    /**
     * 根据视频尺寸比例，以及当前view的尺寸，计算出满足视频比例的view的尺寸
     * @param originalWidth view原来的宽
     * @param originalHeight view原来的高
     * @param ratio 视频宽高比
     * @return 计算后的view的尺寸
     */
    public static Size calculateSizeAsRatio(int originalWidth, int originalHeight, float ratio) {
        PointF p = new PointF();
        if(originalWidth > originalHeight) {
            p.y = originalHeight;
            p.x = originalHeight * ratio;
        } else {
            p.x = originalWidth;
            p.y = originalWidth / ratio;
        }

        return new Size((int)p.x, (int)p.y);
    }

}
